<template>
  <div style="width: 300px; padding: 20px">
    <el-select style="margin-bottom: 20px" v-model="year" placeholder="输入年">
      <el-option v-for="item in years" :key="item" :label="item" :value="item"> </el-option>
    </el-select>
    <el-select style="margin-bottom: 20px" v-model="month" placeholder="输入月">
      <el-option v-for="item in months" :key="item" :label="item" :value="item"> </el-option>
    </el-select>
    <el-button style="margin-bottom: 20px" type="primary" @click="download1">导出下载清单</el-button>
    <el-button style="margin-bottom: 20px" type="primary" @click="download2">导出上传清单</el-button>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const thisYear = new Date().getFullYear();
const years = ref<number[]>([]);
const year = ref('');
const month = ref('');
const months = ref<number[]>([]);
for (let i = thisYear - 1; i <= thisYear; i++) {
  years.value.push(i);
}
for (let i = 1; i <= 12; i++) {
  months.value.push(i);
}

const download1 = () => {
  const period = year.value.toString() + '-' + (100 + month.value).toString().substring(1, 3);
  const url = 'api/DownloadHistory/Excel?period=' + period;
  const a = document.createElement('a');
  a.setAttribute('target', '_blank');
  a.setAttribute('href', url);
  a.click();
};
const download2 = () => {
  const period = year.value.toString() + '-' + (100 + month.value).toString().substring(1, 3);
  const url = 'api/Image/Excel?period=' + period;
  const a = document.createElement('a');
  a.setAttribute('target', '_blank');
  a.setAttribute('href', url);
  a.click();
};
</script>
